﻿using System;
using WindowsFormsApplication5;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ch341aSPIHelperDebugger
{
    public partial class eDP_Setting : Form
    {
        
        public eDP_Setting frm_eDP_Setting;
        public spihelper frm_main;
        spihelper frm_help = null;

        //public extern void IIC_communication_BY_USB(byte device, byte slave_address, byte reg_address, byte reg_data);

        public eDP_Setting(spihelper eDP_Setting)
        {
            frm_help = eDP_Setting;
            InitializeComponent();
            frm_help.Child_window_hide_already = true;
            frm_help.Child_Gamma_Window_Open_Enable = false;//防止重复开启子窗体   
        }

        private void eDP_Setting_FormClosed(object sender, FormClosedEventArgs e)
        {
            frm_help.Child_Gamma_Window_Open_Enable = true; //允许其他子窗体打开
            frm_help.Child_window_hide_already = false;
        }

        float Scaler_H = 0;
        float Scaler_V = 0;
        int Rx_H_total = 0;
        int Rx_HDP = 0;
        int Rx_HBP = 0;
        int Rx_HFP = 0;
        int Rx_HPW = 0;
        int Rx_V_total = 0;
        int Rx_VDP = 0;
        int Rx_VBP = 0;
        int Rx_VFP = 0;
        int Rx_VPW = 0;

        int Tx_H_total = 0;
        int Tx_HDP = 0;
        int Tx_HBP = 0;
        int Tx_HFP = 0;
        int Tx_HPW = 0;
        int Tx_V_total = 0;
        int Tx_VDP = 0;
        int Tx_VBP = 0;
        int Tx_VFP = 0;
        int Tx_VPW = 0;
        int Lane_num = 1;///1:1 lane;    2 =2lane   ;  4=4lane;
        int depth = 1;///0 = 6bit depth ;1 = 8bit depth;
        int Lane_speed = 0;//0 = 1.62G;    1= 2.7G
        byte MN_enable = 0;
        byte SC_enable = 0;


        private void Timing_setting_max()
        {
            int max_setting = 3841;/////设定参数最大值不超过3841
            if (int.Parse(textBox2.Text) > max_setting) 
            { textBox2.Text = "0"; }
            if (int.Parse(textBox3.Text) > max_setting) 
            { textBox3.Text = "0"; }
            if (int.Parse(textBox4.Text) > max_setting) 
            { textBox4.Text = "0"; }
            if (int.Parse(textBox5.Text) > max_setting) 
            { textBox5.Text = "0"; }

            if (int.Parse(textBox6.Text) > max_setting) 
            { textBox6.Text = "0"; }
            if (int.Parse(textBox7.Text) > max_setting) 
            { textBox7.Text = "0"; }
            if (int.Parse(textBox8.Text) > max_setting) 
            { textBox8.Text = "0"; }
            if (int.Parse(textBox9.Text) > max_setting) 
            { textBox9.Text = "0"; }

            if (int.Parse(textBox11.Text) > max_setting) 
            { textBox11.Text = "0"; }
            if (int.Parse(textBox12.Text) > max_setting) 
            { textBox12.Text = "0"; }
            if (int.Parse(textBox13.Text) > max_setting) 
            { textBox13.Text = "0"; }
            if (int.Parse(textBox14.Text) > max_setting) 
            { textBox14.Text = "0"; }

            if (int.Parse(textBox16.Text) > max_setting) 
            { textBox16.Text = "0"; }
            if (int.Parse(textBox17.Text) > max_setting) 
            { textBox17.Text = "0"; }
            if (int.Parse(textBox18.Text) > max_setting) 
            { textBox18.Text = "0"; }
            if (int.Parse(textBox19.Text) > max_setting) 
            { textBox19.Text = "0"; }
        }

        private void Timing_calculate()
        {
            
            ///RX
            textBox1.Text = Convert.ToString(int.Parse(textBox2.Text) + int.Parse(textBox3.Text) + int.Parse(textBox4.Text) + int.Parse(textBox5.Text));
            textBox10.Text = Convert.ToString(int.Parse(textBox9.Text) + int.Parse(textBox8.Text) + int.Parse(textBox7.Text) + int.Parse(textBox6.Text));

            if ((scaler_Box1.Checked == true)&&(int.Parse(textBox2.Text) != 0)&&(int.Parse(textBox9.Text) != 0))////判断是否启用了Scaler模式
            {
                /////计算H方向上需要缩放的倍率
                Scaler_H =  float.Parse(textBox14.Text) / float.Parse(textBox2.Text);/////Scaler_H = TX_HDP / RX_HDP;
                textBox13.Text = Convert.ToString(Convert.ToInt32(int.Parse(textBox3.Text) * Scaler_H));////HFP
                textBox12.Text = Convert.ToString(Convert.ToInt32(int.Parse(textBox4.Text) * Scaler_H));////HBP
                textBox11.Text = Convert.ToString(Convert.ToInt32(int.Parse(textBox5.Text) * Scaler_H));////HPW
                Tx_HFP = int.Parse(textBox13.Text);
                Tx_HBP = int.Parse(textBox12.Text);
                Tx_HPW = int.Parse(textBox11.Text);

                /////计算V方向上需要缩放的倍率
                Scaler_V = float.Parse(textBox19.Text) / float.Parse(textBox9.Text);/////Scaler_V = TX_VDP / RX_VDP;
                textBox18.Text = Convert.ToString(Convert.ToInt32(int.Parse(textBox8.Text) * Scaler_V));////VFP
                textBox17.Text = Convert.ToString(Convert.ToInt32(int.Parse(textBox7.Text) * Scaler_V));////VBP
                textBox16.Text = Convert.ToString(Convert.ToInt32(int.Parse(textBox6.Text) * Scaler_V));////VPW
                Tx_VFP = int.Parse(textBox18.Text);
                Tx_VBP = int.Parse(textBox17.Text);
                Tx_VPW = int.Parse(textBox16.Text);
            }
            ////TX
            textBox15.Text = Convert.ToString(int.Parse(textBox14.Text) + int.Parse(textBox13.Text) + int.Parse(textBox12.Text) + int.Parse(textBox11.Text));
            textBox20.Text = Convert.ToString(int.Parse(textBox19.Text) + int.Parse(textBox18.Text) + int.Parse(textBox17.Text) + int.Parse(textBox16.Text));
            Tx_H_total = int.Parse(textBox15.Text);
            Tx_V_total = int.Parse(textBox20.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            UI_scale_changed(this,e);
            // UI_scale_changed(null,null);
            Application.DoEvents();//重点，必须加上，UI更新

            if (scaler_Box1.Checked == true)
            {
                Timing_setting_max();
                Application.DoEvents();//重点，必须加上，UI更新
                Timing_calculate();
                Application.DoEvents();//重点，必须加上，UI更新
                setting_code_genaration();
            }
            else
            {
                setting_code_genaration();
                //MessageBox.Show(
                //    "**********************************" + "\r\n" +
                //    "没有开启Scale模式，此次不进行时序匹配计算" + "\r\n" +
                //    "**********************************");
            }

        }
        private int value_max_check(int value_data)
        {
            int max_vale = 3841;

            if (value_data <= 0) 
            {
                value_data = 0; 
            }
            if (value_data >= max_vale)
            {
                value_data = 0; 
            }
            return value_data;
        }
        private void Timing_check()
        {
            Rx_HBP = value_max_check(Rx_HBP);
            Rx_HFP = value_max_check(Rx_HFP);
            Rx_HDP = value_max_check(Rx_HDP);
            Rx_HPW = value_max_check(Rx_HPW);

            Rx_VBP = value_max_check(Rx_VBP);
            Rx_VFP = value_max_check(Rx_VFP);
            Rx_VDP = value_max_check(Rx_VDP);
            Rx_VPW = value_max_check(Rx_VPW);

            Tx_HBP = value_max_check(Tx_HBP);
            Tx_HFP = value_max_check(Tx_HFP);
            Tx_HDP = value_max_check(Tx_HDP);
            Tx_HPW = value_max_check(Tx_HPW);

            Tx_VBP = value_max_check(Tx_VBP);
            Tx_VFP = value_max_check(Tx_VFP);
            Tx_VDP = value_max_check(Tx_VDP);
            Tx_VPW = value_max_check(Tx_VPW);
        }

        private void eDP_Timing_Read(object sender, EventArgs e)
        {
            byte temp_read = 0;
            
            if (frm_help.Device_status == true)/////串口有连接时，可以回读时序值。
            {
                //temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0x0F, temp_read);////回读reset状态
                //textBox5.Text = Convert.ToString(temp_read);

                /////回读edp桥接芯片收到的RGB信号的H-line时序
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xE0, temp_read);/////回读H-total upper 8bit
                Rx_H_total = temp_read << 8;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xe1, temp_read);/////回读H-total lower 8bit
                Rx_H_total = Rx_H_total + temp_read;
                
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xE2, temp_read);/////回读HBP+HPW upper 8bit
                Rx_HBP = temp_read << 8;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xe3, temp_read);/////HBP+HPW lower 8bit
                Rx_HBP = Rx_HBP + temp_read;

                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xE4, temp_read);/////回读HDP upper 8bit
                Rx_HDP = temp_read << 8;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xe5, temp_read);/////回读HDP lower 8bit
                Rx_HDP = Rx_HDP + temp_read;
                
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xED, temp_read);/////回读HPW 8bit
                Rx_HPW =  temp_read;

                /////回读edp桥接芯片收到的RGB信号的V-line时序
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xE6, temp_read);/////回读V-total upper 8bit
                Rx_V_total = temp_read << 8;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xe7, temp_read);/////回读V-total lower 8bit
                Rx_V_total = Rx_V_total + temp_read;

                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xE8, temp_read);/////回读VBP+VPW upper 8bit
                Rx_VBP = temp_read << 8;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xe9, temp_read);/////VBP+VPW lower 8bit
                Rx_VBP = Rx_VBP + temp_read;

                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xEA, temp_read);/////回读VDP upper 8bit
                Rx_VDP = temp_read << 8;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xeB, temp_read);/////回读VDP lower 8bit
                Rx_VDP = Rx_VDP + temp_read;

                temp_read = frm_help.IIC_communication_BY_USB(0, 0xe1, 0xEF, temp_read);/////回读VPW 8bit
                Rx_VPW = temp_read;

                Timing_check();

                textBox1.Text = Convert.ToString(Rx_H_total);////H-total 显示
                textBox2.Text = Convert.ToString(Rx_HDP);////HDP 显示
                textBox3.Text = Convert.ToString(Rx_H_total - Rx_HBP- Rx_HDP);////HFP 显示
                textBox4.Text = Convert.ToString(Rx_HBP - Rx_HPW);////HBP 显示
                textBox5.Text = Convert.ToString(Rx_HPW);////HPW 显示

                textBox10.Text = Convert.ToString(Rx_V_total);////V-total 显示
                textBox9.Text = Convert.ToString(Rx_VDP);////VDP 显示
                textBox8.Text = Convert.ToString(Rx_V_total - Rx_VBP - Rx_VDP);////VFP 显示
                textBox7.Text = Convert.ToString(Rx_VBP - Rx_VPW);////VBP 显示
                textBox6.Text = Convert.ToString(Rx_VPW);////VPW 显示

                /*
                801038
                801110
                801201   ////KEY WORD

                813000   ////HDP LOW 8BIT
                813100  //// = H-TOTAL - HDP 
                813200  ////HDP HIGH 8BIT
                813300  ////VDP LOW 8BIT
                813400  ////= V-TOTAL - VDP
                813500  ////VDP HIGH 8BIT
                813600  ////HFP
                813700  ////HPW
                813800  ////VFP+VPW
                813900*/
                frm_help.IIC_communication_BY_USB(0, 0x80, 0x10, 0x38);/////??
                frm_help.IIC_communication_BY_USB(0, 0x80, 0x11, 0x10);/////??
                frm_help.IIC_communication_BY_USB(0, 0x80, 0x12, 0x01);/////??
                temp_read = frm_help.IIC_communication_BY_USB(0, 0x81, 0x30, temp_read);/////回读VPW 8bit
                Tx_HDP = temp_read ;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0x81, 0x32, temp_read);/////回读VPW 8bit
                Tx_HDP = Tx_HDP + ((temp_read>>4)<<8);

                temp_read = frm_help.IIC_communication_BY_USB(0, 0x81, 0x33, temp_read);/////回读VPW 8bit
                Tx_VDP = temp_read;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0x81, 0x35, temp_read);/////回读VPW 8bit
                Tx_VDP = Tx_VDP + ((temp_read>>4)<<8);

                temp_read = frm_help.IIC_communication_BY_USB(0, 0x81, 0x36, temp_read);/////HFP 
                Tx_HFP = temp_read;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0x81, 0x37, temp_read);/////HPW
                Tx_HPW = temp_read;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0x81, 0x31, temp_read);/////回读H-TOTAL - HDP  
                Tx_HBP = temp_read - Tx_HFP - Tx_HPW;

                temp_read = frm_help.IIC_communication_BY_USB(0, 0x81, 0x38, temp_read);/////VFP+VPW
                Tx_VPW = temp_read&0x0F;
                Tx_VFP = (temp_read & 0xF0)>>4;
                temp_read = frm_help.IIC_communication_BY_USB(0, 0x81, 0x34, temp_read);/////V-TOTAL - VDP
                Tx_VBP = temp_read - Tx_VPW - Tx_VFP;

                Timing_check();

                //////tx TIMING  显示
                textBox14.Text = Convert.ToString(Tx_HDP);////HDP 显示
                textBox13.Text = Convert.ToString(Tx_HFP);////HFP 显示
                textBox12.Text = Convert.ToString(Tx_HBP);////HBP 显示
                textBox11.Text = Convert.ToString(Tx_HPW);////HPW 显示

                textBox19.Text = Convert.ToString(Tx_VDP);////VDP 显示
                textBox18.Text = Convert.ToString(Tx_VFP);////VFP 显示
                textBox17.Text = Convert.ToString(Tx_VBP);////VBP 显示
                textBox16.Text = Convert.ToString(Tx_VPW);////VPW 显示

                ////TX
                textBox15.Text = Convert.ToString(int.Parse(textBox14.Text) + int.Parse(textBox13.Text) + int.Parse(textBox12.Text) + int.Parse(textBox11.Text));
                textBox20.Text = Convert.ToString(int.Parse(textBox19.Text) + int.Parse(textBox18.Text) + int.Parse(textBox17.Text) + int.Parse(textBox16.Text));
            }
            else
            {
                MessageBox.Show(
                    "**********************************" + "\r\n" +
                    "串口未连接，无法回读！！！" + "\r\n" +
                    "**********************************");
            }
        }
        private byte Lane_setting(byte temp_setting)
        {
            byte temp = 0;
            if (lane_Button3.Checked == true)
            {
                Lane_num = 4;
            }
            if (lane_Button2.Checked == true)
            {
                Lane_num = 2;
            }
            if (lane_Button1.Checked == true)
            {
                Lane_num = 1;
            }

            if (radioButton1.Checked == true)
            {
                Lane_speed = 1;
            }
            else if (radioButton2.Checked == true)
            {
                Lane_speed = 0;
            }
            else
            {
                Lane_speed = 0;
            }

            if (Bit_Button1.Checked == true)
            {
                depth = 1;
            }
            if (Bit_Button2.Checked == true)
            {
                depth = 0;
            }



            switch (Lane_num)
            {
                case 1:
                    temp = 0x01;
                    break;
                case 2:
                    temp = 0x02;
                    break;
                case 4:
                    temp = 0x04;
                    break;
                default:
                    temp = 0x01;
                    break;
            }
            if (Lane_speed == 0) 
            {
                temp += 0x10; 
            }
            if (depth == 1)
            {
                temp += 0x20;
            }
            temp += 0xC0;
            temp_setting = temp;
            return temp_setting;
        }

        private void setting_code_genaration()
        {
            byte temp00 = 0;
            { /*
             e00f01
            e00004
            e00200
            e00604
            e007c4
            e00901
            e00b00

            e0100a
            e011a1
            e01200
            e01370
            e0140a
            e01500
            e01605
            e017c9
            e01800
            e01926
            e01a05
            e01ba0
            e01c80
            e01d20
            e01e80
            e01f05
            e0200a
            e021a0
            e02200
            e02370
            e0240a
            e02500
            e02605
            e027c9
            e02800
            e02926
            e02a05
            e02ba0
            e02c00
            e02d20
            e02e00
            e02f05
            e05508
            e05600
            e05700
            e05808
            e05900
            e05a00
            e05d3d
            e05e7a
            e05fa0

            e06000
            e07101
            e07380
            e07420
            ea00b0
            ea0100
            ea025c
            ea0b47
            ea0e05
            ea0f05
            ea11bb
            ea2200
            ea8410
            ea8532
            ea00b1
            e00f00

             */
            }
            frm_help.dataw.Text = "";
            frm_help.dataw.Text = "e00f01" + Environment.NewLine;
            frm_help.dataw.Text += "e00004" + Environment.NewLine;
            if (scaler_Box1.Checked == true)
            {
                frm_help.dataw.Text += "e00200" + Environment.NewLine;
            }
            else
            {
                frm_help.dataw.Text += "e00207" + Environment.NewLine;
            }

            frm_help.dataw.Text += "e00606" + Environment.NewLine;
            //frm_help.dataw.Text += "e007c4" + Environment.NewLine;
            frm_help.dataw.Text += "e007" + string.Format("{0:X2}", (Lane_setting(temp00))) + Environment.NewLine;
            frm_help.dataw.Text += "e00901" + Environment.NewLine;
            frm_help.dataw.Text += "e00b00" + Environment.NewLine;

            if(scaler_Box1.Checked == true)
            {
                frm_help.dataw.Text += "e010" + string.Format("{0:X2}", (int.Parse(textBox1.Text) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e011" + string.Format("{0:X2}", (int.Parse(textBox1.Text) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e012" + string.Format("{0:X2}", ((Rx_HBP) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e013" + string.Format("{0:X2}", ((Rx_HBP) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e014" + string.Format("{0:X2}", ((Rx_HDP) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e015" + string.Format("{0:X2}", ((Rx_HDP) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e016" + string.Format("{0:X2}", (int.Parse(textBox10.Text) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e017" + string.Format("{0:X2}", (int.Parse(textBox10.Text) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e018" + string.Format("{0:X2}", ((Rx_VBP) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e019" + string.Format("{0:X2}", ((Rx_VBP) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e01a" + string.Format("{0:X2}", ((Rx_VDP) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e01b" + string.Format("{0:X2}", ((Rx_VDP) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e01c" + string.Format("{0:X2}", ((128))) + Environment.NewLine;
                frm_help.dataw.Text += "e01d" + string.Format("{0:X2}", ((Rx_HPW))) + Environment.NewLine;
                frm_help.dataw.Text += "e01e" + string.Format("{0:X2}", ((128))) + Environment.NewLine;
                frm_help.dataw.Text += "e01f" + string.Format("{0:X2}", ((Rx_VPW))) + Environment.NewLine;
                frm_help.dataw.Text += "e020" + string.Format("{0:X2}", (int.Parse(textBox15.Text) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e021" + string.Format("{0:X2}", (int.Parse(textBox15.Text) % 256)) + Environment.NewLine;

                frm_help.dataw.Text += "e022" + string.Format("{0:X2}", ((Tx_HPW + Tx_HBP) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e023" + string.Format("{0:X2}", ((Tx_HPW + Tx_HBP) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e024" + string.Format("{0:X2}", ((Tx_HDP) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e025" + string.Format("{0:X2}", ((Tx_HDP) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e026" + string.Format("{0:X2}", (int.Parse(textBox20.Text) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e027" + string.Format("{0:X2}", (int.Parse(textBox20.Text) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e028" + string.Format("{0:X2}", ((Tx_VPW + Tx_VBP) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e029" + string.Format("{0:X2}", ((Tx_VPW + Tx_VBP) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e02a" + string.Format("{0:X2}", ((Tx_VDP) / 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e02b" + string.Format("{0:X2}", ((Tx_VDP) % 256)) + Environment.NewLine;
                frm_help.dataw.Text += "e02c" + string.Format("{0:X2}", ((0))) + Environment.NewLine;
                frm_help.dataw.Text += "e02d" + string.Format("{0:X2}", ((Tx_HPW))) + Environment.NewLine;
                frm_help.dataw.Text += "e02e" + string.Format("{0:X2}", ((0))) + Environment.NewLine;
                frm_help.dataw.Text += "e02f" + string.Format("{0:X2}", ((Tx_VPW))) + Environment.NewLine;

                Scaler_H = float.Parse(textBox2.Text) / float.Parse(textBox14.Text);
                Scaler_H = Scaler_H * 524288;
                frm_help.dataw.Text += "e055" + string.Format("{0:X2}", ((Convert.ToInt64(Scaler_H)) & 0xff0000) >> 16) + Environment.NewLine;
                frm_help.dataw.Text += "e056" + string.Format("{0:X2}", ((Convert.ToInt64(Scaler_H)) & 0x00ff00) >> 8) + Environment.NewLine;
                frm_help.dataw.Text += "e057" + string.Format("{0:X2}", (Convert.ToInt64(Scaler_H)) & 0x0000FF) + Environment.NewLine;
                Scaler_V = float.Parse(textBox9.Text) / float.Parse(textBox19.Text);
                Scaler_V = Scaler_V * 524288;
                frm_help.dataw.Text += "e058" + string.Format("{0:X2}", ((Convert.ToInt64(Scaler_V)) & 0xff0000) >> 16) + Environment.NewLine;
                frm_help.dataw.Text += "e059" + string.Format("{0:X2}", ((Convert.ToInt64(Scaler_V)) & 0x00ff00) >> 8) + Environment.NewLine;
                frm_help.dataw.Text += "e05a" + string.Format("{0:X2}", (Convert.ToInt64(Scaler_V)) & 0x0000FF) + Environment.NewLine;

                frm_help.dataw.Text += "e05d" + string.Format("{0:X2}", ((int.Parse(textBox15.Text) * int.Parse(textBox20.Text)) & 0xff0000) >> 16) + Environment.NewLine;
                frm_help.dataw.Text += "e05e" + string.Format("{0:X2}", ((int.Parse(textBox15.Text) * int.Parse(textBox20.Text)) & 0x00ff00) >> 8) + Environment.NewLine;
                frm_help.dataw.Text += "e05f" + string.Format("{0:X2}", ((int.Parse(textBox15.Text) * int.Parse(textBox20.Text)) & 0x0000FF)) + Environment.NewLine;
            }
            frm_help.dataw.Text += "e06000" + Environment.NewLine;
            if (radioButton5.Checked == true)
            {
                frm_help.dataw.Text += "e07101" + Environment.NewLine;
            }
            else
            {
                frm_help.dataw.Text += "e07100" + Environment.NewLine;
            }
            
            frm_help.dataw.Text += "e07380" + Environment.NewLine;
            if (depth == 0)
            {
                frm_help.dataw.Text += "e07420" + Environment.NewLine;
            }
            else
            {
                frm_help.dataw.Text += "e07400" + Environment.NewLine;
            }
            if (Lane_speed == 0)
            {
                frm_help.dataw.Text += "ea0020" + Environment.NewLine;
            }
            else
            {
                frm_help.dataw.Text += "ea00b0" + Environment.NewLine;
            }
                
            frm_help.dataw.Text += "ea0100" + Environment.NewLine;
            if (Lane_speed == 1) 
            {
                frm_help.dataw.Text += "ea025c" + Environment.NewLine;
            }
            else 
            {
                frm_help.dataw.Text += "ea0258" + Environment.NewLine;
            }
            frm_help.dataw.Text += "ea0b47" + Environment.NewLine;
            frm_help.dataw.Text += "ea0e05" + Environment.NewLine;
            frm_help.dataw.Text += "ea0f05" + Environment.NewLine;
            frm_help.dataw.Text += "ea11bb" + Environment.NewLine;
            frm_help.dataw.Text += "ea2200" + Environment.NewLine;
            frm_help.dataw.Text += "ea8410" + Environment.NewLine;
            frm_help.dataw.Text += "ea8532" + Environment.NewLine;
            if (Lane_speed == 0)
            {
                frm_help.dataw.Text += "ea0021" + Environment.NewLine;
            }
            else 
            {
                frm_help.dataw.Text += "ea00b1" + Environment.NewLine;
            }
            frm_help.dataw.Text += "e00f00" + Environment.NewLine;

            frm_help.dataw.Text +=  Environment.NewLine;////end
        }

        private void Speed_changed(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                Lane_speed = 1;
            }
            else if(radioButton2.Checked == true)
            {
                Lane_speed = 0;
            }
            else
            {
                Lane_speed = 0;
            }
        }

        private void Depth_changed(object sender, EventArgs e)
        {
            if (Bit_Button1.Checked == true)
            {
                depth = 1;
            }
            if (Bit_Button2.Checked == true)
            {
                depth = 0;
            }
            
        }

        private void Lane_num_changed(object sender, EventArgs e)
        {
            if (lane_Button3.Checked == true)
            {
                Lane_num = 4;
            }
            if (lane_Button2.Checked == true)
            { 
                Lane_num = 2; 
            }
            if (lane_Button1.Checked == true)
            {
                Lane_num = 1;
            }
        }

        //private void UI_scale_changed()
        //{
        //    /////开启了scaler模式则UI更新
        //    if (scaler_Box1.Checked == true)
        //    {
        //        textBox2.Enabled = true;

        //    }
        //    else/////关闭了scaler模式则UI更新
        //    {
        //        textBox2.Enabled = false;
        //    }
        //}

        private void UI_scale_changed(object sender, EventArgs e)
        {
            /////开启了scaler模式则UI更新
            if (scaler_Box1.Checked == true)
            {
                textBox2.Enabled = true;
                textBox3.Enabled = true;
                textBox4.Enabled = true;
                textBox5.Enabled = true;

                textBox9.Enabled = true;
                textBox8.Enabled = true;
                textBox7.Enabled = true;
                textBox6.Enabled = true;

                textBox14.Enabled = true;
                textBox13.Enabled = true;
                textBox12.Enabled = true;
                textBox11.Enabled = true;

                textBox19.Enabled = true;
                textBox18.Enabled = true;
                textBox17.Enabled = true;
                textBox16.Enabled = true;
            }
            else/////关闭了scaler模式则UI更新
            {
                textBox2.Enabled = false;
                textBox3.Enabled = false;
                textBox4.Enabled = false;
                textBox5.Enabled = false;

                textBox9.Enabled = false;
                textBox8.Enabled = false;
                textBox7.Enabled = false;
                textBox6.Enabled = false;

                textBox14.Enabled = false;
                textBox13.Enabled = false;
                textBox12.Enabled = false;
                textBox11.Enabled = false;

                textBox19.Enabled = false;
                textBox18.Enabled = false;
                textBox17.Enabled = false;
                textBox16.Enabled = false;
            }
        }
    }
}
